package com.fdb.efp.console.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 需求编号【2019D0509】
 *
 * @author qiuyf
 * @version 0.1 初始为0.1,后续变更则修改
 * @since 2020/3/16 11:10
 */
@Configuration
public class TaskConfiguration {

    @Value("${applicationThreadPool.corePoolSize}")
    private int corePoolSize;

    @Value("${applicationThreadPool.maxTaskNum}")
    private int maxTaskNum;

    @Value("${applicationThreadPool.queueSize}")
    private int queueSize;


    @Bean("taskExecutor")
    public ThreadPoolTaskExecutor taskExecutor(){
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(corePoolSize);
        taskExecutor.setMaxPoolSize(maxTaskNum);
        taskExecutor.setQueueCapacity(queueSize);
        taskExecutor.setThreadNamePrefix("asyncTask");
        return taskExecutor;
    }
}
